<?php

namespace App\Strategies;

use App\Constants\ProductConstant;
use App\Helpers\DateUtils;
use App\Helpers\LinkUtils;
use App\Helpers\RestUtils;
use App\Helpers\Utils;
use App\Models\ComModelFactory;
use App\Models\Factory\CommentFactory;
use App\Models\Factory\ProductFactory;
use App\Services\Core\Store\Qiniu\QiniuService;
use App\Strategies\AppStrategy;

/**
 * 产品公共策略
 *
 * Class UserStrategy
 * @package App\Strategies
 */
class ProductStrategy extends AppStrategy
{
    /**
     * @param $product
     * @return \stdClass
     * 返回首页诱导轮播产品数据
     */
    public static function getPromotions($product, $applyPeoples, $register)
    {
        foreach ($product as $key => $val) {
            $product[$key]['product_logo'] = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
        }
        $productArr['list']      = $product ? $product : RestUtils::getStdObj();
        $productArr['apply_num'] = bcadd($applyPeoples, $register);
        return $productArr;
    }

    /**
     * @param $productTag
     * 返回速贷攻略数据
     */
    public static function getGuides($productTag, $pageCount)
    {
        foreach ($productTag as $key => $val) {
            $productTag[$key]['product_logo'] = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
        }
        $product['list']      = $productTag ? $productTag : RestUtils::getStdObj();
        $product['pageCount'] = $pageCount;

        return $product;
    }

    /**
     * @param $product
     * 返回最新产品图片
     */
    public static function getNewsOlines($product)
    {
        foreach ($product as $key => $val) {
            $product[$key]['product_logo']      = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
            $product[$key]['product_introduct'] = Utils::removeHTML($val['product_introduct']);
        }
        return $product ? $product : [];
    }

    /**
     * @param $specialLists
     * 返回分类专题对应产品数据
     */
    public static function getSpecials($specialIds, $specialLists, $pageCount)
    {
        $result       = [];
        $productIdArr = explode(',', $specialIds['product_list']);
        foreach ($productIdArr as $key => $value) {
            foreach ($specialLists as $k => $val) {
                if ($value == $val['platform_product_id']) {
                    $result[$key]                = $val;
                    $result[$key]['productType'] = 5;
                }
            }
        }

        //处理图片 
        foreach ($result as $rkey => $rval) {
            $result[$rkey]['product_logo']  = QiniuService::getProductImgs($rval['product_logo'], $rval['platform_product_id']);
            $result[$rkey]['success_count'] = DateUtils::ceilMoney($rval['success_count']);
            $result[$rkey]['star']          = $rval['loan_max'];
        }
        $result             = array_values($result);
        $datas['list']      = $result ? $result : RestUtils::getStdObj();
        $datas['pageCount'] = $pageCount;
        $datas['title']     = isset($specialIds['title']) ? $specialIds['title'] : '';
        $datas['img']       = isset($specialIds['img']) ? QiniuService::getImgs($specialIds['img']) : '';
        return $datas;
    }

    /**
     * @param int $type
     * @param array $product
     * @param int $countPage
     * @return mixed
     * 全部产品详情
     */
    public static function productAll($type = 1, $product = [], $countPage = 0)
    {
        switch ($type) {
            case 1:     //定位排序
                foreach ($product as $key => $val) {
                    $product[$key]['position_sort']     = $val['position_sort'];
                    $rate                               = $val['composite_rate'];
                    $speed                              = $val['loan_speed'];
                    $exper                              = $val['experience'];
                    $star                               = bcdiv(bcadd($exper, bcadd($rate, $speed)), 3, 1);
                    $product[$key]['star']              = !empty($star) ? $star : '4.0';
                    $product[$key]['product_logo']      = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
                    $product[$key]['tag_name']          = !empty($val['tag_name']) ? $val['tag_name'] : array();
                    $product[$key]['success_count']     = DateUtils::ceilMoney($val['success_count']);
                    $product[$key]['product_introduct'] = ComModelFactory::escapeHtml($val['product_introduct']);
                    $product[$key]['productType']       = intval($type);
                }
                $dataAll['list']      = $product;
                $dataAll['pageCount'] = $countPage;
                return $dataAll;
                break;
            case 2:     //成功率
                foreach ($product as $key => $val) {
                    $star                               = bcadd($val['success_rate'], 0, 1);
                    $product[$key]['star']              = !empty($star) ? $star : '4.0';
                    $product[$key]['product_logo']      = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
                    $product[$key]['tag_name']          = !empty($val['tag_name']) ? $val['tag_name'] : array();
                    $product[$key]['success_count']     = DateUtils::ceilMoney($val['success_count']);
                    $product[$key]['product_introduct'] = ComModelFactory::escapeHtml($val['product_introduct']);
                    $product[$key]['productType']       = intval($type);
                }
                $dataAll['list']      = $product;
                $dataAll['pageCount'] = $countPage;
                return $dataAll;
                break;
            case 3:     //放款速度
                foreach ($product as $key => $val) {
                    $star                               = bcadd($val['loan_speed'], 0, 1);
                    $product[$key]['star']              = !empty($star) ? $star : '4.0';
                    $product[$key]['product_logo']      = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
                    $product[$key]['tag_name']          = !empty($val['tag_name']) ? $val['tag_name'] : array();
                    $product[$key]['success_count']     = DateUtils::ceilMoney($val['success_count']);
                    $product[$key]['product_introduct'] = ComModelFactory::escapeHtml($val['product_introduct']);
                    $product[$key]['productType']       = intval($type);
                }
                $dataAll['list']      = $product;
                $dataAll['pageCount'] = $countPage;
                return $dataAll;
                break;
            case 4:     //贷款利率
                foreach ($product as $key => $val) {
                    $star                               = bcadd($val['composite_rate'], 0, 1);
                    $product[$key]['star']              = !empty($star) ? $star : '4.0';
                    $product[$key]['product_logo']      = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
                    $product[$key]['tag_name']          = !empty($val['tag_name']) ? $val['tag_name'] : array();
                    $product[$key]['success_count']     = DateUtils::ceilMoney($val['success_count']);
                    $product[$key]['product_introduct'] = ComModelFactory::escapeHtml($val['product_introduct']);
                    $product[$key]['productType']       = intval($type);
                }
                $dataAll['list']      = $product;
                $dataAll['pageCount'] = $countPage;
                return $dataAll;
                break;
            case 5:     //最高额度
                foreach ($product as $key => $val) {
                    $star                               = bcadd($val['loan_max'], 0);
                    $product[$key]['star']              = !empty($star) ? $star : '';
                    $product[$key]['product_logo']      = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
                    $product[$key]['tag_name']          = !empty($val['tag_name']) ? $val['tag_name'] : array();
                    $product[$key]['success_count']     = DateUtils::ceilMoney($val['success_count']);
                    $product[$key]['product_introduct'] = ComModelFactory::escapeHtml($val['product_introduct']);
                    $product[$key]['productType']       = intval($type);
                }
                $dataAll['list']      = $product;
                $dataAll['pageCount'] = $countPage;
                return $dataAll;
                break;
        }
    }

    /**
     * @param $product
     * 返回信用卡数据
     */
    public static function getCreditCards($creditcardArr)
    {
        foreach ($creditcardArr as $key => $val) {
            $count                                = bcadd($val['loan_speed'], bcadd($val['composite_rate'], $val['experience']));
            $creditcardArr[$key]['star']          = bcdiv($count, 3, 1);                                                  //综合指数
            $creditcardArr[$key]['comment_count'] = CommentFactory::commentAll($val['platform_product_id']);               //评论次数
            $creditcardArr[$key]['success_count'] = DateUtils::formatMoney($val['success_count']);                         //成功申请次数
            $creditcardArr[$key]['product_logo']  = QiniuService::getProductImgs($val['product_logo'], $val['platform_product_id']);
        }
        return $creditcardArr;
    }

    /**
     * @param $calcuLists
     * 返回计算器数据
     */
    public static function getCalculators($productArr)
    {
        //利率
        $lilv                           = self::intRateStr($productArr['interest_alg']);
        $productArr['interest_alg_num'] = $productArr['interest_alg'];
        $productArr['interest_alg']     = $lilv;
        $productArr['interest_rate']    = self::rateValue($productArr['min_rate']);
        //每期利息 || 一次性还款
        $productArr['pay_method'] = self::interestPay($productArr['pay_method']);
        if ($productArr['pay_method'] == 1) {
            $productArr['method'] = ProductConstant::REPAYMENT;
        } else {
            $productArr['method'] = ProductConstant::EACH_INTEREST;
        }
        //计算的最终结果
        //$datas['calculatedValue']   = Product::calculateRate($productArr,$data);
        //金额

        return $productArr;
    }

    /**
     * @param $loanMax
     * 通过产品最高金额与最高金额   获取对应的金额金额
     */
    public static function getMoneyData($productArr)
    {
        //截取数组
        $calculatorMoney    = ProductConstant::CALCULATOR_MONEY;
        $calculatorMoneyInt = ProductConstant::CALCULATOR_MONEY_INT;

        //比较两个数组
        $min = ProductStrategy::getMin($calculatorMoneyInt, $productArr['loan_min'], 1);
        $max = ProductStrategy::getMax($calculatorMoneyInt, $productArr['loan_max'], 1);

        return ProductStrategy::getSliceDatas($calculatorMoney, $min, $max);
    }

    /**
     * @param $productArr
     * @return array
     * 通过产品最高金额与最高期限   获取对应的期限范围
     */
    public static function getTermData($productArr)
    {
        $calculatorTerm    = ProductConstant::CALCULATOR_TERM;
        $calculatorTermInt = ProductConstant::CALCULATOR_TERM_INT;

        //比较两个数组
        $min = ProductStrategy::getMin($calculatorTermInt, $productArr['period_min'], 2);
        $max = ProductStrategy::getMax($calculatorTermInt, $productArr['period_max'], 2);
        return ProductStrategy::getSliceDatas($calculatorTerm, $min, $max);
    }

    /**
     * @param array $datas
     * @param $param
     * 常量与数组对比  取最小值
     */
    public static function getMin($params = [], $param, $type)
    {
        $min = 0;
        foreach ($params as $calKey => $calValue) {
            if ($param <= $params[0]) {
                $min = $params[0];
            } elseif ($param > $params[$calKey] && $param <= $params[$calKey + 1]) {
                $min = $params[$calKey + 1];
            }
        }
        switch ($type) {
            case 1: //金额
                return DateUtils::formatMoneyToInt($min);
                break;
            case 2://期限
                return DateUtils::formatTimeToYear($min);
                break;
        }
    }

    /**
     * @param array $params
     * @param $param
     * @param $type
     * @return string
     * 常量与数组对比  取最大值
     */
    public static function getMax($params = [], $param, $type)
    {
        $max = 0;
        foreach ($params as $calKey => $calValue) {
            if ($param <= $params[0]) {
                $max = $params[0];
            } elseif ($param >= $params[$calKey]) {
                $max = $params[$calKey];
            }
        }

        switch ($type) {
            case 1: //金额
                return $max = DateUtils::formatMoneyToInt($max);
                break;
            case 2://期限
                return $max = DateUtils::formatTimeToYear($max);
                break;
        }

    }


    /**
     * @param array $params
     * @param $min
     * @param $max
     * @return array
     * 截取数组长度
     */
    public static function getSliceDatas($params = [], $min, $max)
    {
        $minKey = array_search($min, $params);
        $maxKey = array_search($max, $params);
        $minArr = array_slice($params, $minKey);
        $maxArr = array_slice($params, $maxKey + 1);
        $data   = array_diff($minArr, $maxArr);
        return $data ? $data : [];
    }


    /**
     * @param $product
     * 返回产品详情数据
     */
    public static function getDetails($productTag, $productId)
    {
        $product                          = [];
        $product['platform_product_id']   = $productTag['platform_product_id'];
        $product['platform_id']           = $productTag['platform_id'];
        $product['platform_product_name'] = isset($productTag['platform_product_name']) ? $productTag['platform_product_name'] : '';
        $product['product_logo']          = QiniuService::getProductImgs($productTag['product_logo'], $productTag['platform_product_id']);
        $product['tag_name']              = isset($productTag['tag_name']) ? $productTag['tag_name'] : [];
        $product['platform_name']         = isset($productTag['platform_name']) ? $productTag['platform_name'] : '';
        //申请人评价
        $product['success_num']   = self::successCompare($productTag['success_count']);
        $product['success_width'] = self::imgWidth($product['success_num']);
        $product['success_count'] = DateUtils::ceilMoney($productTag['success_count']);
        $product['fast_num']      = self::fastCompare($productTag['loan_speed']);
        $product['fast_width']    = self::imgWidth($product['fast_num']);
        $product['fast_time']     = isset($productTag['fast_time']) ? $productTag['fast_time'] : 0;
        $successRate              = ProductFactory::passRate($productTag['platform_product_id']);
        $product['pass_num']      = self::passCompare($successRate);
        $product['pass_width']    = self::imgWidth($product['pass_num']);
        $product['comment_count'] = CommentFactory::commentAllCount($productId);
        //广告图片
        $product['banner_img'] = QiniuService::getImgs($productTag['banner_img']);
        //申请条件
        $product['apply_condition'] = isset($productTag['apply_condition']) ? ComModelFactory::escapeHtml($productTag['apply_condition']) : '';
        //申请流程
        $product['process'] = ProductFactory::applicationProcess($productTag['apply_process_ids']);
        //借款细节
        $product['loan_detail'] = self::loanDetail($productTag);
        //新手指导
        $product['guide'] = isset($productTag['guide']) ? ComModelFactory::escapeHtml($productTag['guide']) : '';
        //产品优势
        $product['product_introduct'] = isset($productTag['product_introduct']) ? ComModelFactory::escapeHtml($productTag['product_introduct']) : '';
        //查看攻略
        $product['news_link'] = isset($productTag['news_link']) ? $productTag['news_link'] : '';
        //分享链接
        $product['h5_link'] = LinkUtils::productShare($productId);
        //申请借款开关判断
        $product['apply_button_text_flag'] = 'v2.5.1';
        $product['apply_button_text']      = '查看攻略';
        //print_r($product);die();
        return $product;
    }

    /**
     * @param $data
     * @param $productIdArr
     * @param $keyed
     * 分类专题——产品列表
     */
    public static function getSpecialProducts($data, $productIdArr, $keyed)
    {
        $pageSize = isset($data['pageSize']) ? $data['pageSize'] : 1;
        $pageNum  = isset($data['pageNum']) ? $data['pageNum'] : 5;
        $datas    = [];

        foreach ($productIdArr as $pkey => $pval) {
            foreach ($keyed as $key => $val) {
                if ($key == $pval) {
                    $datas[] = $val;
                }
            }
        }

        $product = DateUtils::pageInfo($datas, $pageSize, $pageNum);
        return $product ? $product : [];
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    //计算器
    public static function intRateStr($data)
    {
        $i = DateUtils::toInt($data);
        if ($i == 1) return '参考月利率';
        elseif ($i == 2) return '参考日利率';
        elseif ($i == 3) return '参考年利率';
        elseif ($i == 4) return '手续费';
        else return '';

    }

    /**
     * @param $data
     * @return string
     * @desc    显示“参考月利率”或者“参考日利率”从后台获取状态
     * 利率百分比从后台获取，获取不到时按1%月利率计算，并弹POP提示：获取数据失败，请重新加载
     * 计算器
     */
    public static function rateValue($data)
    {
        $value = floatval($data) . '';
        if (empty($data)) return '1';
        else return $value;
    }

    /**
     * @param $data
     * @return string
     * 除了一次性还款 其余的都为每期利息
     * 一次性还款 1 每期利息 2
     * 计算器
     */
    public static function interestPay($data)
    {
        $i = intval($data);
        if ($i == 3) return 1;
        else return 2;
    }

    /**
     * @param $data
     * 本金=在“主要变量”上那个金额处的选值，若金额处没有值，每期利息便显示“未选金额”
     * 期限=在“主要变量”上那个期限的选值，若期限处没有值，一次性还款便显示“未选期限”
     * @param $data
     * 每期利息： 【除了一次性还款其余的都为每期利息】
     * 金额=本金 x 每月利率/每日利率
     * 一次性还款：   9
     * 金额=本金 x每月利率/日利率 x 存款期限
     * 计算器
     */
    public static function calculateRate($product, $data)
    {
        $payMethod   = intval($product['pay_method']);
        $balance     = isset($data['balance']) ? intval($data['balance']) : '';
        $balanceTime = isset($data['balanceTime']) ? intval($data['balanceTime']) : '';
        //每月利率
        $yueRate = isset($data['min_rate']) ? $data['min_rate'] : 1;
        if (empty($balance)) {
            return $calculatedValue = '未选金额';
        } else if ($payMethod == 3 && empty($balanceTime)) {
            return $calculatedValue = '未选期限';
        } else if ($payMethod == 3 && !empty($balanceTime)) {
            //一次性还款
            return $calculatedValue = bcmul(bcmul($balance, $yueRate), $balanceTime);
        } else {
            //每期还款
            return $calculatedValue = bcmul($balance, $yueRate);
        }

    }

    /**
     * @param $data
     * @return string
     * @desc    欢迎程度转化
     * api4
     */
    public static function successCompare($data)
    {
        $i = DateUtils::toInt($data);
        if ($i <= 2000) return ProductConstant::COUHE;
        elseif ($i >= 2001 && $i <= 5000) return ProductConstant::ORDINARY;
        elseif ($i >= 5001 && $i <= 10000) return ProductConstant::GOOD;
        elseif ($i >= 10001 && $i <= 30000) return ProductConstant::BETTER;
        elseif ($i >= 30001 && $i <= 50000) return ProductConstant::BEST;
        elseif ($i >= 50001) return ProductConstant::EXCELLENT;
        else return '';
    }

    /**
     * @param $data
     * @return string
     * @desc    速度评价转化 根据放款速度满意度评价
     * api4
     */
    public static function fastCompare($data)
    {
        $i = floatval($data);
        if ($i <= 3) return ProductConstant::COUHE;
        elseif ($i >= 3.1 && $i <= 3.4) return ProductConstant::ORDINARY;
        elseif ($i >= 3.5 && $i <= 3.9) return ProductConstant::GOOD;
        elseif ($i >= 4.0 && $i <= 4.4) return ProductConstant::BETTER;
        elseif ($i >= 4.5 && $i <= 4.9) return ProductConstant::BEST;
        elseif ($i == 5.0) return ProductConstant::EXCELLENT;
        else return '';
    }

    /**
     * @param $data
     * @return string
     * @desc    通过概率转化  （已授信人数+已放款人数）/（已授信人数+已放款人数+被拒绝的人数）
     * api4
     */
    public static function passCompare($data)
    {
        $i = floatval($data);
        if ($i <= 0.1) return ProductConstant::COUHE;
        elseif ($i >= 0.11 && $i <= 0.2) return ProductConstant::ORDINARY;
        elseif ($i >= 0.21 && $i <= 0.4) return ProductConstant::GOOD;
        elseif ($i >= 0.41 && $i <= 0.6) return ProductConstant::BETTER;
        elseif ($i >= 0.61 && $i <= 0.8) return ProductConstant::BEST;
        elseif ($i >= 0.81 && $i <= 1) return ProductConstant::EXCELLENT;
        else return '';
    }

    /**
     * @param $data
     * @return int|string
     * @desc    通过概率转化图片的宽度
     * api4
     */
    public static function imgWidth($data)
    {
        $i = trim($data);
        if ($i == ProductConstant::COUHE) return 30;
        elseif ($i == ProductConstant::ORDINARY) return 60;
        elseif ($i == ProductConstant::GOOD) return 90;
        elseif ($i == ProductConstant::BETTER) return 120;
        elseif ($i == ProductConstant::BEST) return 150;
        elseif ($i == ProductConstant::EXCELLENT) return 208;
        else return '';
    }


    /**
     * @param $data
     * @return mixed
     * @desc    产品详情
     * api4
     */
    public static function loanDetail($data)
    {
        $loan = [];
        //借款用途
        $loan[0]['title']   = !empty($data['to_use']) ? '借款用途' : '';
        $loan[0]['content'] = self::toUse($data['to_use']);
        //面向人群
        $loan[1]['title']   = !empty($data['user_group']) ? '面向人群' : '';
        $loan[1]['content'] = self::userGroup($data['user_group']);
        //审核方式
        $loan[2]['title']   = !empty($data['check_way']) ? '审核方式' : '';
        $loan[2]['content'] = self::checkWayToStr($data['check_way']);
        //到账方式
        $loan[3]['title']   = !empty($data['accept_method']) ? '到账方式' : '';
        $loan[3]['content'] = self::acceptMethod($data['accept_method']);
        //服务费
        $loan[4]['title']   = !empty($data['fee']) ? '服务费' : '';
        $loan[4]['content'] = isset($data['fee']) ? $data['fee'] : '';
        //到账金额 real_accept_money
        $loan[5]['title']   = !empty($data['real_accept_money']) ? '到账金额' : '';
        $loan[5]['content'] = self::realAcceptMoneyToStr($data['real_accept_money'], $data['real_other']);
        //还款方式
        $loan[6]['title']   = !empty($data['pay_method']) ? '还款方式' : '';
        $loan[6]['content'] = self::payMethodToStr($data['pay_method'], $data['pay_method_other']);
        //提前还款
        $loan[7]['title']   = !empty($data['is_ahead_pay']) ? '提前还款' : '';
        $loan[7]['content'] = self::isAheadPayToStr($data['is_ahead_pay'], $data['is_ahead_pay_other']);
        //逾期算法
        $loan[8]['title']   = !empty($data['overdue_alg']) ? '逾期算法' : '';
        $loan[8]['content'] = $data['overdue_alg'];
        //所属平台
        $loan[9]['title']   = !empty($data['platform_name']) ? '所属平台' : '';
        $loan[9]['content'] = isset($data['platform_name']) ? $data['platform_name'] : '';
        //过滤空数组
        foreach ($loan as $key => $val) {
            if ($val['title'] == '') {
                unset($loan[$key]);
            }
        }
        $loanData = array_values($loan);
        return $loanData;
    }

    //to_use 处理 api4
    public static function toUse($toUse)
    {
        $i = DateUtils::toInt($toUse);
        if ($i == 1) return '还信用卡';
        elseif ($i == 2) return '现金借贷';
        else return '';
    }

    //user_group 处理 api4
    public static function userGroup($userGroup)
    {
        $groupArr = explode(',', $userGroup);
        $groupArr = array_filter($groupArr);
        foreach ($groupArr as $key => $val) {
            $groupArr[$key] = self::userGroupToStr($val);
        }
        return implode($groupArr, "\\");
    }

    //user_group 转化成汉字      api4
    public static function userGroupToStr($data)
    {
        $i = DateUtils::toInt($data);
        if ($i == 1) return '学生';
        elseif ($i == 2) return '上班族';
        elseif ($i == 3) return '企业主';
        elseif ($i == 4) return '其他';
        else return '';
    }

    //check_way审核方式转化成汉字    api4
    public static function checkWayToStr($data)
    {
        $i = DateUtils::toInt($data);
        if ($i == 1) return '线下审批';
        elseif ($i == 2) return '电话复审';
        elseif ($i == 3) return '自动审批';
        else return '';
    }

    //accept_method 到账方式转化成汉字   api4
    public static function acceptMethod($data)
    {
        $accessMethod = explode(',', $data);
        foreach ($accessMethod as $key => $val) {
            $accessMethod[$key] = self::acceptMethodToStr($val);
        }
        return implode($accessMethod, '、');
    }

    //accept_method 到账方式转化成汉字   api4
    public static function acceptMethodToStr($data)
    {
        $i = DateUtils::toInt($data);
        if ($i == 1) return '银行卡';
        elseif ($i == 2) return '信用卡';
        elseif ($i == 3) return '支付宝';
        else return '';
    }

    //pay_method 还款方式转化成汉字  api4
    public static function payMethodToStr($data, $other)
    {
        $i = DateUtils::toInt($data);
        if ($i == 1) return '等额本息';
        elseif ($i == 2) return '等额本金';
        elseif ($i == 3) return '一次性还清';
        elseif ($i == 9) return $other;
        else return '';
    }

    //is_ahead_pay 提前还款转化成汉字    api4
    public static function isAheadPayToStr($data, $other)
    {
        $i = DateUtils::toInt($data);
        if ($i == 1) return '不可以';
        elseif ($i == 2) return '可以, 即时算息';
        elseif ($i == 3) return '可以, 利息全收';
        elseif ($i == 4) return '可以, 收违约金';
        elseif ($i == 9) return $other;
        else return '';
    }

    //is_ahead_pay 到账金额转化成汉字    api4
    public static function realAcceptMoneyToStr($data, $other)
    {
        $i = DateUtils::toInt($data);
        if ($i == 1) return '全额到账';
        elseif ($i == 2) return '扣除服务费';
        elseif ($i == 3) return '扣除服务费和利息';
        elseif ($i == 4) return '可以, 收违约金';
        elseif ($i == 9) return $other;
        else return '';
    }


}
